home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / OpenTransport / Open Transport 1.0.5b4 / Open Transport SDK / Open Tpt Module Developer / Includes / mistream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-24  |  14.8 KB  |  441 lines  |  [TEXT/MPS ]

  1. /** Copyright (c) 1989-1994  Mentat Inc.
  2.  ** stream.h 4.7, last change 10 Apr 1994
  3.  **/
  4.  
  5. #ifndef _MPS_STREAM_
  6. #define _MPS_STREAM_
  7.  
  8. #if OTKERNEL
  9.  
  10. /* defines module or driver */
  11. struct streamtab 
  12. {
  13.     struct qinit*    st_rdinit;        /* defines read QUEUE */
  14.     struct qinit*    st_wrinit;        /* defines write QUEUE */
  15.     struct qinit*    st_muxrinit;    /* for multiplexing drivers only */
  16.     struct qinit*    st_muxwinit;    /* ditto */
  17. };
  18.  
  19. typedef struct queue 
  20. {
  21.     struct qinit*    q_qinfo;    /* procedures and limits for queue */
  22.     struct msgb*     q_first;    /* head of message queue */
  23.     struct msgb*     q_last;        /* tail of message queue */
  24.     struct queue*    q_next;        /* next queue in Stream */
  25.     union 
  26.     {
  27.         struct queue*    q_u_link;     /* link to scheduling queue */
  28.         struct sqh_s*    q_u_sqh_parent;
  29.     } q_u;
  30.     char*            q_ptr;        /* to private data structure */
  31.     unsigned long    q_count;    /* weighted count of characters on q */
  32.     long            q_minpsz;    /* min packet size accepted */
  33.     long            q_maxpsz;    /* max packet size accepted */
  34.     unsigned long    q_hiwat;    /* high water mark, for flow control */
  35.     unsigned long    q_lowat;    /* low water mark */
  36.     struct qband*    q_bandp;    /* band information */
  37.     unsigned short    q_flag;     /* %%% queue state */
  38.     unsigned char    q_nband;    /* %%% number of bands */
  39.     unsigned char    q_pad1[1];    /* %%% reserved */
  40.     struct q_xtra*    q_osx;        /* Pointer to OS-dependent extra stuff */
  41.     struct queue*    q_ffcp;        /* Forward flow control pointer */
  42.     struct queue*    q_bfcp;        /* Backward flow control pointer */
  43. } queue_t;
  44.  
  45. #define q_link            q_u.q_u_link
  46. #define q_sqh_parent    q_u.q_u_sqh_parent
  47.  
  48. /* queue_t flag defines */
  49. #define QREADR                    0x1     /* This queue is a read queue */
  50. #define QNOENB                    0x2     /* Don't enable in putq */
  51. #define QFULL                    0x4     /* The queue is full */
  52. #define QWANTR                    0x8     /* The queue should be scheduled in the next putq */
  53. #define QWANTW                    0x10    /* The stream should be back enabled when this queue drains */
  54. #define QUSE                    0x20    /* The queue is allocated and ready for use */
  55. #define QENAB                    0x40    /* The queue is scheduled (on the run queue) */
  56. #define QBACK                    0x80    /* The queue has been back enabled */
  57. #define QOLD                    0x100    /* Module supports old style opens and closes */
  58. #define QHLIST                    0x200    /* The Stream head is doing something with this queue (Not supported by MPS) */
  59. #define QWELDED                 0x400    /* Mentat flag for welded queues */
  60. #define    QUNWELDING                0x800    /* Queue is scheduled to be unwelded */
  61. #define    QPROTECTED                0x1000    /* Mentat flag for unsafe q access */
  62.  
  63. typedef struct qband 
  64. {
  65.     struct qband*    qb_next;    /* next band for this queue */
  66.     unsigned long    qb_count;    /* weighted count of characters in this band */ 
  67.     struct msgb*     qb_first;     /* head of message queue */
  68.     struct msgb*     qb_last;    /* tail of message queue */
  69.     unsigned long    qb_hiwat;    /* high water mark */
  70.     unsigned long    qb_lowat;    /* low water mark */
  71.     unsigned short    qb_flag;    /* %%% state */
  72.     short            qb_pad1;    /* %%% reserved */
  73. } qband_t;
  74.  
  75. /* qband_t flag defines */
  76. #define QB_FULL         0x1             /* The band is full */
  77. #define QB_WANTW        0x2             /* The stream should be back enabled when this band/queue drains */
  78. #define QB_BACK         0x4             /* The queue has been back enabled */
  79.  
  80. typedef    int    (* _CDECL putp_t)(queue_t *, struct msgb *);
  81. typedef    int    (* _CDECL srvp_t)(queue_t *);
  82. typedef int (* _CDECL admin_t)(void);
  83. typedef void (* _CDECL bufcall_t)(long);
  84. typedef int    (* _CDECL openp_t)(queue_t*, dev_t*, int, int, cred_t*);
  85. typedef int (* _CDECL closep_t)(queue_t*, int, cred_t*);
  86. typedef int    (* _CDECL openOld_t)(queue_t*, dev_t, int, int);
  87. typedef int (* _CDECL closeOld_t)(queue_t*);
  88.  
  89. struct qinit 
  90. {
  91.     putp_t        qi_putp;                /* put procedure */
  92.     srvp_t        qi_srvp;                /* service procedure */
  93.     openp_t        qi_qopen;                /* called on each open or a push */
  94.     closep_t    qi_qclose;                 /* called on last close or a pop */
  95.     admin_t        qi_qadmin;                 /* reserved for future use */
  96.     struct module_info* qi_minfo;        /* information structure */
  97.     struct module_stat* qi_mstat;        /* statistics structure - optional */
  98. };
  99.  
  100. struct module_info 
  101. {
  102.     unsigned short    mi_idnum;        /* module ID number */
  103.     char*            mi_idname;        /* module name */
  104.     long            mi_minpsz;        /* min pkt size, for developer use */
  105.     long            mi_maxpsz;        /* max pkt size, for developer use */
  106.     unsigned long    mi_hiwat;        /* hi-water mark, for flow control */
  107.     unsigned long    mi_lowat;        /* lo-water mark, for flow control */
  108. };
  109.  
  110. #else
  111.  
  112. typedef int    queue_t;
  113.  
  114. #endif    /* OTKERNEL */
  115.  
  116. /* message block */
  117.  
  118. #if GENERATINGPOWERPC
  119. #pragma options align=mac68k
  120. #endif
  121.  
  122. typedef struct msgb 
  123. {
  124.     struct msgb*     b_next;        /* next message on queue */
  125.     struct msgb*     b_prev;        /* previous message on queue */
  126.     struct msgb*     b_cont;        /* next message block of message */
  127.     unsigned char*    b_rptr;        /* first unread data byte in buffer */
  128.     unsigned char*    b_wptr;        /* first unwritten data byte */
  129.     struct datab*    b_datap;    /* data block */
  130.     unsigned char    b_band;     /* message priority */
  131.     unsigned char    b_pad1;
  132.     unsigned short    b_flag;
  133. #ifdef    MSGB_XTRA
  134.     MSGB_XTRA
  135. #endif
  136. } mblk_t;
  137.  
  138. #if GENERATINGPOWERPC
  139. #pragma options align=reset
  140. #endif
  141.  
  142. /* mblk flags */
  143. #define MSGMARK         0x01            /* last byte of message is tagged */
  144. #define MSGNOLOOP        0x02            /* don't pass message to write-side of stream */
  145. #define MSGDELIM        0x04            /* message is delimited */
  146. #define MSGNOGET        0x08
  147.  
  148. /* data descriptor */
  149.  
  150. typedef struct datab 
  151. {
  152.     union 
  153.     {
  154.         struct datab*    freep;
  155.         struct free_rtn* frtnp;
  156.     } db_f;
  157.     unsigned char*    db_base;        /* first byte of buffer */
  158.     unsigned char*    db_lim;            /* last byte+1 of buffer */
  159.     unsigned char    db_ref;         /* count of messages pointing to block*/
  160.     unsigned char    db_type;        /* message type */
  161.     unsigned char    db_iswhat;        /* message status */
  162.     unsigned char    db_filler2;        /* for spacing */
  163.     unsigned int    db_size;        /* used internally */
  164.     unsigned char*    db_msgaddr;     /* used internally */
  165.     long            db_filler;
  166. } dblk_t;
  167. #define db_freep        db_f.freep
  168. #define db_frtnp        db_f.frtnp
  169.  
  170. /* Free return structure for esballoc */
  171. typedef struct free_rtn 
  172. {
  173.     void    (* _CDECL free_func)(char* arg);     /* Routine to call to free buffer */
  174.     char*    free_arg;                             /* Parameter to free_func */
  175. } frtn_t;
  176.  
  177. /* Message types */
  178. #define QNORM            0
  179. #define M_DATA            0                /* Ordinary data */
  180. #define M_PROTO         1                /* Internal control info and data */
  181. #define M_BREAK         010             /* Request a driver to send a break */
  182. #define M_PASSFP        011             /* Used to pass a file pointer */
  183. #define M_SIG            013             /* Requests a signal to be sent */
  184. #define M_DELAY         014             /* Request a real-time delay */
  185. #define M_CTL            015             /* For inter-module communication */
  186. #define M_IOCTL         016             /* Used internally for I_STR requests */
  187. #define M_SETOPTS        020             /* Alters characteristics of Stream head */
  188. #define M_RSE            021             /* Reserved for internal use */
  189.  
  190. /* MPS private type */
  191. #define M_MI            0100
  192. #define M_MI_READ_RESET    1
  193. #define M_MI_READ_SEEK       2
  194. #define M_MI_READ_END       4
  195.  
  196. /* Priority messages types */
  197. #define QPCTL            0200
  198. #define M_IOCACK        0201            /* Positive ack of previous M_IOCTL */
  199. #define M_IOCNAK        0202            /* Previous M_IOCTL failed */
  200. #define M_PCPROTO        0203            /* Same as M_PROTO except for priority */
  201. #define M_PCSIG         0204            /* Priority signal */
  202. #define M_FLUSH         0206            /* Requests modules to flush queues */
  203. #define M_STOP            0207            /* Request drivers to stop output */
  204. #define M_START         0210            /* Request drivers to start output */
  205. #define M_HANGUP        0211            /* Driver can no longer produce data */
  206. #define M_ERROR         0212            /* Reports downstream error condition */
  207. #define M_READ            0213            /* Reports client read at Stream head */
  208. #define M_COPYIN        0214            /* Requests the Stream to copy data in for a module */
  209. #define M_COPYOUT        0215            /* Requests the Stream to copy data out for a module */
  210. #define M_IOCDATA        0216            /* Status from M_COPYIN/M_COPYOUT message */
  211. #define M_PCRSE         0220            /* Reserved for internal use */
  212. #define M_STOPI         0221            /* Request drivers to stop input */
  213. #define M_STARTI        0222            /* Request drivers to start input */
  214. #define M_HPDATA        0223            /* MPS-private type; high priority data */
  215.  
  216. /* Defines for flush messages */
  217. #define FLUSHALL        1
  218. #define FLUSHDATA        0
  219.  
  220. #define NOERROR         -1                /* used in M_ERROR messages */
  221.  
  222. /* structure contained in M_COPYIN/M_COPYOUT messages */
  223. struct copyreq 
  224. {
  225.     int             cq_cmd;         /* ioctl command (from ioc_cmd) */
  226.     struct cred*    cq_cr;            /* pointer to full credentials */
  227.     unsigned int    cq_id;            /* ioctl id (from ioc_id) */
  228.     unsigned char*    cq_addr;        /* address to copy data to/from */
  229.     unsigned int    cq_size;        /* number of bytes to copy */
  230.     int             cq_flag;        /* state */
  231.     mblk_t*            cq_private;        /* private state information */
  232.     long            cq_filler[4];
  233. };
  234. #define cq_uid    cq_cr->cr_uid
  235. #define cq_gid    cq_cr->cr_gid
  236.  
  237. /* copyreq defines */
  238. #define STRCANON        0x1             /* b_cont data block contains canonical format specifier */
  239. #define RECOPY            0x2             /* perform I_STR copyin again this time using canonical format specifier */
  240.  
  241. /* structure contained in M_IOCDATA message block */
  242. struct copyresp 
  243. {
  244.     int             cp_cmd;         /* ioctl command (from ioc_cmd) */
  245.     struct cred*    cp_cr;            /* pointer to full credentials */
  246.     unsigned int    cp_id;            /* ioctl id (from ioc_id) */
  247.     unsigned char*    cp_rval;        /* status of request; 0 for success; error value for failure */
  248.     unsigned int    cp_pad1;
  249.     int             cp_pad2;
  250.     mblk_t*            cp_private;        /* private state information */
  251.     long            cp_filler[4];
  252. };
  253. #define cp_uid    cp_cr->cr_uid
  254. #define cp_gid    cp_cr->cr_gid
  255.  
  256. /* structure contained in an M_IOCTL message block */
  257. struct iocblk 
  258. {
  259.     int             ioc_cmd;        /* ioctl command type */
  260.     struct cred*    ioc_cr;            /* pointer to full credentials */
  261.     unsigned int    ioc_id;         /* ioctl id */
  262.     unsigned int    ioc_count;        /* count of bytes in data field */
  263.     int             ioc_error;        /* error code */
  264.     int             ioc_rval;        /* return value */
  265.     long            ioc_filler[4];
  266. };
  267. #define ioc_uid ioc_cr->cr_uid
  268. #define ioc_gid ioc_cr->cr_gid
  269.  
  270. #define TRANSPARENT             -1        /* ioc_count value for transparent ioctl's */
  271.  
  272. /* Used in M_IOCTL mblks to muxes (ioc_cmd I_LINK) */
  273. struct linkblk 
  274. {
  275.     struct queue* l_qtop;        /* lowest level write queue of upper stream */
  276.     struct queue* l_qbot;        /* highest level write queue of lower stream */
  277.     int     l_index;        /* system-unique index for lower stream */
  278.     long        l_pad[5];
  279. };
  280.  
  281. /* structure contained in an M_PASSFP message block */
  282. struct strpfp 
  283. {
  284.     unsigned long    pass_file_cookie;        /* file 'pointer' */
  285.     unsigned short    pass_uid;                /* user id of sending stream */
  286.     unsigned short    pass_gid;
  287.     struct sth_s*    pass_sth;             /* Stream head pointer of passed stream */
  288. };
  289.  
  290. /* structure contained in an M_SETOPTS message block */
  291. struct stroptions 
  292. {
  293.     unsigned long so_flags; /* options to set */
  294.     short            so_readopt;     /* read option */
  295.     unsigned short    so_wroff;        /* write offset */
  296.     long            so_minpsz;        /* minimum read packet size */
  297.     long            so_maxpsz;        /* maximum read packet size */
  298.     unsigned long    so_hiwat;        /* read queue high-water mark */
  299.     unsigned long    so_lowat;        /* read queue low-water mark */
  300.     unsigned char    so_band; /* band for water marks */
  301.     unsigned long    so_poll_set;    /* poll events to set */
  302.     unsigned long    so_poll_clr;    /* poll events to clear */
  303. };
  304. /* definitions for so_flags field */
  305. #define SO_ALL            0x7fff    /* Update all options */
  306. #define SO_READOPT        0x0001    /* Set the read mode */
  307. #define SO_WROFF        0x0002    /* Insert an offset in write M_DATA mblks */
  308. #define SO_MINPSZ        0x0004    /* Change the min packet size on sth rq */
  309. #define SO_MAXPSZ        0x0008    /* Change the max packet size on sth rq */
  310. #define SO_HIWAT        0x0010    /* Change the high water mark on sth rq */
  311. #define SO_LOWAT        0x0020    /* Change the low water mark */
  312. #define SO_MREADON        0x0040    /* Request M_READ messages */
  313. #define SO_MREADOFF     0x0080    /* Don't gen M_READ messages */
  314. #define SO_NDELON        0x0100    /* old TTY semantics for O_NDELAY reads and writes */
  315. #define SO_NDELOFF        0x0200    /* STREAMS semantics for O_NDELAY reads and writes */
  316. #define SO_ISTTY        0x0400    /* Become a controlling tty */
  317. #define SO_ISNTTY        0x0800    /* No longer a controlling tty */
  318. #define SO_TOSTOP        0x1000    /* Stop on background writes */
  319. #define SO_TONSTOP        0x2000    /* Don't stop on background writes */
  320. #define SO_BAND         0x4000    /* Water marks are for a band */
  321. #define SO_POLL_SET        0x8000    /* Set events to poll */
  322. #define SO_POLL_CLR        0x10000    /* Clear events to poll */
  323.  
  324. /* Buffer Allocation Priority */
  325. #define BPRI_LO         1
  326. #define BPRI_MED        2
  327. #define BPRI_HI         3
  328.  
  329. #ifndef INFPSZ
  330. #define INFPSZ            -1
  331. #endif
  332.  
  333. /** Test whether message is a data message */
  334. #define datamsg(type)    ((type) == M_DATA || (type) == M_PROTO || (type) == M_PCPROTO  ||  (type) == M_DELAY)
  335.  
  336. #if OTKERNEL
  337.  
  338. /** Re-allow a queue to be scheduled for service */
  339. #define enableok(q)     ((q)->q_flag &= ~QNOENB)
  340.  
  341. /** Prevent a queue from being scheduled */
  342. #define noenable(q)     ((q)->q_flag |= QNOENB)
  343.  
  344. /** Get pointer to the mate queue */
  345. #define OTHERQ(q)        (((q)->q_flag & QREADR) ? WR(q) : RD(q))
  346.  
  347. /** Get pointer to the read queue, assumes 'q' is a write queue ptr */
  348. #define RD(q)    (&q[-1])
  349.  
  350. /** Get pointer to the write queue, assumes 'q' is a read queue ptr */
  351. #define WR(q)    (&q[1])
  352.  
  353. #endif    /* OTKERNEL */
  354.  
  355. #define CLONEOPEN        0x2
  356. #define MODOPEN         0x1
  357. #define OPENFAIL        -1
  358.  
  359. /* Enumeration values for strqget and strqset */
  360. typedef enum qfields {
  361.     QHIWAT    = 0,
  362.     QLOWAT    = 1,
  363.     QMAXPSZ    = 2,
  364.     QMINPSZ    = 3,
  365.     QCOUNT    = 4,
  366.     QFIRST    = 5,
  367.     QLAST    = 6,
  368.     QFLAG    = 7,
  369.     QBAD    = 8
  370. } qfields_t;
  371.  
  372. #ifdef __cplusplus
  373. extern "C" {
  374. #endif
  375.  
  376. #if OTKERNEL
  377.  
  378. mblk_t*        allocb(size_t size, int pri);
  379. queue_t*    allocq(void);
  380. int            adjmsg(mblk_t*, int len_param);
  381. queue_t*    backq(queue_t*);
  382.  
  383. int        bcanput(queue_t*, uchar_p pri);
  384. int        bcanputnext(queue_t*, uchar_p pri);
  385. int        bufcall(size_t memNeeded, int pri, bufcall_t,    // %%%
  386.                 long context);
  387. int        canput(queue_t*);
  388. int        canputnext(queue_t*);
  389. mblk_t*    copyb(mblk_t*);
  390. mblk_t*    copymsg(mblk_t*);
  391. mblk_t*    dupb(mblk_t*);
  392. mblk_t*    dupmsg(mblk_t*);
  393. mblk_t*    esballoc(unsigned char* base, size_t size, int pri, frtn_t*);
  394. void    flushband(queue_t*, uchar_p pri, int flag);
  395. void    flushq(queue_t*, int flag);
  396. void    freeb(mblk_t*);
  397. void    freemsg(mblk_t*);
  398. int        freeq(queue_t*);
  399. int        freezestr(queue_t*);
  400. admin_t    getadmin(ushort_p mid);
  401. unsigned short    getmid(char * name);
  402. mblk_t*    getq(queue_t*);
  403. int        insq(queue_t*, mblk_t* emp, mblk_t* nmp);
  404. void    linkb(mblk_t* mp1, mblk_t* mp2);
  405. int        msgdsize(const mblk_t*);
  406. mblk_t*    msgpullup(mblk_t*, int len);
  407. int        pullupmsg(mblk_t*, int len);
  408. int        putbq(queue_t*, mblk_t*);
  409. int        putctl(queue_t*, int type);
  410. int        putnextctl(queue_t*, int type);
  411. int        putctl1(queue_t*, int type, int c);
  412. int        putnextctl1(queue_t*, int type, int c);
  413. int        putctl2(queue_t*, int type, int c1, int c2);
  414. #ifndef puthere
  415. int        puthere(queue_t*, mblk_t*);
  416. #endif
  417. int        putnext(queue_t*,  mblk_t*);
  418. int        putq(queue_t*, mblk_t*);
  419. void    qenable(queue_t*);
  420. void    qprocson(queue_t*);
  421. void    qprocsoff(queue_t*);
  422. int        qreply(queue_t*, mblk_t*);
  423. int        qsize(queue_t*);
  424. mblk_t*    rmvb(mblk_t * mp, mblk_t * bp);
  425. void    rmvq(queue_t*, mblk_t*);
  426. /* prototype for strlog in strlog.h */
  427. int        strqget(queue_t*, qfields_t what, uchar_p pri, long* valp);
  428. int        strqset(queue_t*, qfields_t what, uchar_p pri, long val);
  429. int        testb(int size, int pri);
  430. void    unbufcall(int id);
  431. void    unfreezestr(queue_t * q, int oldpri);
  432. mblk_t*    unlinkb(mblk_t*);
  433.  
  434. #endif    /* OTKERNEL */
  435.  
  436. #ifdef __cplusplus
  437. };
  438. #endif
  439.  
  440. #endif    /* ifdef _MPS_STREAM_    */
  441.